package com.ylfstu.homework;

import java.util.Arrays;

public class Homework01 {
    public static void main(String[] args) {
        //将指定部分字符串进行反转，比如将"abcdef"反转为"aedcbf"
        String str = "abcdefghijk";
//        System.out.println(str.indexOf("q"));
//        System.out.println(str.indexOf("y"));
        String s = null;
        try {
            s = reverse(str, 1, 6);
        } catch (Exception e) {
            System.out.println(e.getMessage());
            return;
        }
        System.out.println(s);
    }

    public static String reverse(String str, int start, int end) {

        if (!(str != null && start >= 0 && end < str.length() && start < end)) {
            throw new RuntimeException("参数不正确");
        }

        char[] chars = str.toCharArray();
        char temp;
        for (int i = start, j = end; i < j; i++, j--) {
            temp = chars[i];
            chars[i] = chars[end + 1 - i];
            chars[end + 1 - i] = temp;
        }
        return new String(chars);
    }
}
